package scct.chenhui.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {
//   定义数据连接字符串
    private static String dbDriver="com.mysql.cj.jdbc.Driver";
    private static String dbUrl = "jdbc:mysql://localhost:3306/storemanager?characterEncoding=UTF-8&useSSL=false";
    private static String dbUsername = "root";
    private static String dbPassword = "123456";


    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        Class.forName(dbDriver);
        Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
        return connection;
    }

    public static void closeConnection(Connection con) throws Exception {
        if (con != null) {
            con.close();
        }
    }
}
